package com.hzlj.position.dbsync.common.dao;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fz.common.base.converter.QueryWrapperConverterPlus;
import com.hzlj.position.dbsync.common.common.dto.syncOffsetConfig.SyncOffsetConfigQueryResultDTO;
import com.hzlj.position.dbsync.common.common.model.SyncOffsetConfig;
import com.hzlj.position.dbsync.common.mapper.SyncOffsetConfigMapper;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

/**
 * 同步offset配置表(SyncOffsetConfig)表操作类
 *
 * @author lifh
 * @date 2023-11-30 16:00:38
 */
@Repository
public class SyncOffsetConfigDao extends ServiceImpl<SyncOffsetConfigMapper, SyncOffsetConfig> {
    @Resource
    private SyncOffsetConfigMapper syncOffsetConfigMapper;


    public SyncOffsetConfigQueryResultDTO getSyncOffsetConfig(String jgCode, String syncType) {
        return QueryWrapperConverterPlus.of(syncOffsetConfigMapper)
                .selectOne(SyncOffsetConfigQueryResultDTO.class, null, null, q -> q
                        .eq(SyncOffsetConfig::getJgCode, jgCode)
                        .eq(SyncOffsetConfig::getSyncType, syncType)
                );
    }


    /**
     * 修改数据
     */
    public boolean updateSyncOffsetConfig(SyncOffsetConfig sync) {
        LambdaUpdateWrapper<SyncOffsetConfig> updateWrapper = new UpdateWrapper<SyncOffsetConfig>().lambda()
                .eq(SyncOffsetConfig::getJgCode, sync.getJgCode())
                .eq(SyncOffsetConfig::getSyncType, sync.getSyncType());
        return this.update(sync, updateWrapper);
    }

}

